package com.rentong.page;

import com.rentong.json.JsonUtils;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ZXY
 * @ClassName: TreeNode
 * @Description: 树节点
 * @date 2017/10/19 14:27
 */
public class TreeNode {

    //树节点id
    private Integer id;

    //树节点展示名称
    private String text;

    //节点状态 'open' 或 'closed'
    private String state;

    //节点类型
    private Integer type;

    //子节点
    private List<TreeNode> children;

    public TreeNode() {
    }

    public TreeNode(Integer id, String text, Integer type) {
        this.id = id;
        this.text = text;
        this.type = type;
        this.children = new ArrayList<>();
    }

    public TreeNode(Integer id, String text) {
        this.id = id;
        this.text = text;
        this.children = new ArrayList<>();
    }

    public void addChild(TreeNode treeNode) {
        getChildren().add(treeNode);
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public List<TreeNode> getChildren() {
        return children;
    }

    public void setChildren(List<TreeNode> children) {
        this.children = children;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    /**
     * json 序列化输出
     */
    public static void writeJson(TreeNode treeNode, HttpServletResponse response) {
        JsonUtils.sendJsonToPage(treeNode, response);
    }
}
